"use strict"
//查询个人详细信息
const mvc = require("cosjs.mvc");
exports.total = async function () {
    const sid = this.get('sid', 'int');
    let role_mode = mvc.model.mongo('role', sid);
    let role_num = await role_mode.count({});
    let pay_num = await role_mode.count({ 'rmb': { '$gt': 0 } });
    let timestamp = (new Date()).getTime() - 2592000 * 1000;
    //近一个月内登陆过
    let anum = await role_mode.count({ 'login': { '$gt': timestamp } });
    //当天登录用户
    let todaystamp = mvc.library('time/today');
    let tnum = await role_mode.count({ 'login': { '$gt': todaystamp } });
    // console.log('======BobFindMe======');
    // console.log(todaystamp,tnum);
    //总收入
    //     {$match: {time: {$gte: te},uid:{$nin:ids}}},
    //     {$group: {_id: null, sum: {$sum: '$val'}}}
    // ], {}),
    let _income = await role_mode.aggregate([{ $group: { _id: 1, sum: { $sum: '$rmb' } } }], {});
    let _sum = _income['1'] ? _income['1'].sum : 0;

    //在线
    let redis = mvc.model.redis("online");
    let online = await redis.now(sid);
    return { num: role_num, pnum: pay_num, anum: anum, income: _sum, tnum: tnum, 'online': online };
}


